#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   App_CommunicationControl_0x28_test.py
@Time    :   2024/12/06 13:31:28
@Author  :   YangLiang 
@Version :   1.0
@Contact :   yangliang@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

# here put the import lib
from pytest_assume.plugin import assume
 
import pytest
import logging
import time
import requests
from sympy import I
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
from collections.abc import Iterable

from sqlalchemy import false
sys.dont_write_bytecode = True

communicationControl = [    ([0x28,0x00,0x01],[0x68,0x00]),         
                            ([0x28,0x01,0x01],[0x68,0x01]),
                            ([0x28,0x03,0x01],[0x68,0x03]),
                            ([0x28,0x80,0x01],[]),         
                            ([0x28,0x81,0x01],[]),
                            ([0x28,0x83,0x01],[]),
                        ]

communicationControl_NRC12 = [  ([0x28,0x02,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x02,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x04,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x04,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x05,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x05,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x06,0x01],[0x7F,0x28,0x12]),        
                                ([0x28,0x06,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x3F,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x3F,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x40,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x40,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x5F,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x5F,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x60,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x60,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x7E,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x7E,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x7F,0x01],[0x7F,0x28,0x12]),         
                                ([0x28,0x7F,0x03],[0x7F,0x28,0x12]),
                                ([0x28,0x02,0x02],[0x7F,0x28,0x12]),
                            ]

communicationControl_NRC13 = [  ([0x28],[0x7F,0x28,0x13]),                    
                                ([0x28,0x00],[0x7F,0x28,0x13]),
                                ([0x28,0x01],[0x7F,0x28,0x13]),
                                ([0x28,0x03],[0x7F,0x28,0x13]),
                                ([0x28,0x00,0x01,0x15],[0x7F,0x28,0x13]),
                                ([0x28,0x00,0x03,0xFF],[0x7F,0x28,0x13]),  
                                ([0x28,0x01,0x01,0x25],[0x7F,0x28,0x13]),
                                ([0x28,0x01,0x03,0x06],[0x7F,0x28,0x13]),
                                ([0x28,0x03,0x02,0x26],[0x7F,0x28,0x13]),
                                ([0x28,0x03,0x02,0x08],[0x7F,0x28,0x13]),      
                            ]

communicationControl_NRC31 = [  ([0x28,0x00,0x00],[0x7F,0x28,0x31]),     
                                ([0x28,0x01,0x00],[0x7F,0x28,0x31]),
                                ([0x28,0x03,0x00],[0x7F,0x28,0x31]),
                                ([0x28,0x00,0x02],[0x7F,0x28,0x31]),     
                                ([0x28,0x01,0x02],[0x7F,0x28,0x31]),
                                ([0x28,0x03,0x02],[0x7F,0x28,0x31]),
                                ([0x28,0x00,0x03],[0x7F,0x28,0x31]),     
                                ([0x28,0x01,0x03],[0x7F,0x28,0x31]),
                                ([0x28,0x03,0x03],[0x7F,0x28,0x31]),
                                ([0x28,0x00,0x04],[0x7F,0x28,0x31]),             
                                ([0x28,0x01,0x04],[0x7F,0x28,0x31]),
                                ([0x28,0x03,0x04],[0x7F,0x28,0x31]),
                                ([0x28,0x00,0x7F],[0x7F,0x28,0x31]),           
                                ([0x28,0x01,0x7F],[0x7F,0x28,0x31])
                            ]

communicationControl_Supported_NRC12 = [    ([0x28,0x82,0x01],[0x7F,0x28,0x12]),         
                                            ([0x28,0x82,0x03],[0x7F,0x28,0x12]),
                                            ([0x28,0x84,0x01],[0x7F,0x28,0x12]),         
                                            ([0x28,0x84,0x03],[0x7F,0x28,0x12]),
                                            ([0x28,0x85,0x01],[0x7F,0x28,0x12]),         
                                            ([0x28,0x85,0x03],[0x7F,0x28,0x12]),
                                            ([0x28,0x86,0x01],[0x7F,0x28,0x12]),        
                                            ([0x28,0x86,0x03],[0x7F,0x28,0x12]),
                                            ([0x28,0x8F,0x01],[0x7F,0x28,0x12]),         
                                            ([0x28,0x8F,0x03],[0x7F,0x28,0x12]),
                                            ([0x28,0x8E,0x01],[0x7F,0x28,0x12]),         
                                            ([0x28,0x8E,0x03],[0x7F,0x28,0x12]),
                                            ([0x28,0x82,0x02],[0x7F,0x28,0x12]),
                                        ]

communicationControl_Supported_NRC13 = [    ([0x28],[0x7F,0x28,0x13]),                    
                                            ([0x28,0x80],[0x7F,0x28,0x13]),
                                            ([0x28,0x81],[0x7F,0x28,0x13]),
                                            ([0x28,0x83],[0x7F,0x28,0x13]),
                                            ([0x28,0x80,0x01,0x15],[0x7F,0x28,0x13]),
                                            ([0x28,0x80,0x03,0xFF],[0x7F,0x28,0x13]),  
                                            ([0x28,0x81,0x01,0x25],[0x7F,0x28,0x13]),
                                            ([0x28,0x81,0x03,0x06],[0x7F,0x28,0x13]),
                                            ([0x28,0x83,0x02,0x26],[0x7F,0x28,0x13]),
                                            ([0x28,0x83,0x02,0x08],[0x7F,0x28,0x13]),      
                                        ]

communicationControl_Supported_NRC31 = [    ([0x28,0x80,0x00],[0x7F,0x28,0x31]),     
                                            ([0x28,0x81,0x00],[0x7F,0x28,0x31]),
                                            ([0x28,0x83,0x00],[0x7F,0x28,0x31]),
                                            ([0x28,0x80,0x02],[0x7F,0x28,0x31]),     
                                            ([0x28,0x81,0x02],[0x7F,0x28,0x31]),
                                            ([0x28,0x83,0x02],[0x7F,0x28,0x31]),
                                            ([0x28,0x80,0x03],[0x7F,0x28,0x31]),     
                                            ([0x28,0x81,0x03],[0x7F,0x28,0x31]),
                                            ([0x28,0x83,0x03],[0x7F,0x28,0x31]),
                                            ([0x28,0x80,0x04],[0x7F,0x28,0x31]),             
                                            ([0x28,0x81,0x04],[0x7F,0x28,0x31]),
                                            ([0x28,0x83,0x04],[0x7F,0x28,0x31]),
                                            ([0x28,0x80,0x7F],[0x7F,0x28,0x31]),           
                                            ([0x28,0x81,0x7F],[0x7F,0x28,0x31])
                                        ]

communicationControl_DisableRx = [  ([0x28,0x03,0x01],[0x68,0x03]),
                                    ([0x28,0x83,0x01],[]),    
                                ]

communicationControl_DisableTx = [  ([0x28,0x01,0x01],[0x68,0x01]),
                                    ([0x28,0x81,0x01],[]),     
                                    ([0x28,0x03,0x01],[0x68,0x03]),
                                    ([0x28,0x83,0x01],[]),
                                ]





class Test_CommunicationControl_Boot_Phy(object):

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl] 
    @allure.severity('normal')
    @allure.title('Test positive response of 0x28 in programming session with physical addressing')
    @allure.description('Test positive response of 0x28 in programming session with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl,ids=ids)
    def test_CommunicationControl_Programming_Phy(self,action,Driver, req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_NRC12]   
    @allure.severity('minor') 
    @allure.title('Test NRC12 of 0x28 in programming session with physical addressing')        
    @allure.description('Test NRC12 of 0x28 in programming session with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_NRC12,ids=ids)
    def test_CommunicationControl_NRC12_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)  

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_NRC13]   
    @allure.severity('minor') 
    @allure.title('Test NRC13 of 0x28 in programming session with physical addressing')        
    @allure.description('Test NRC13 of 0x28 in programming session with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_NRC13,ids=ids)
    def test_CommunicationControl_NRC13_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)   


    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_NRC31]   
    @allure.severity('minor') 
    @allure.title('Test NRC31 of 0x28 in programming session with physical addressing')        
    @allure.description('Test NRC31 of 0x28 in programming session with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_NRC31,ids=ids)
    def test_CommunicationControl_NRC31_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)            


    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_Supported_NRC12] 
    @allure.severity('normal')
    @allure.title('Test NRC12 negative response code of 0x28 when suppressPosMsgBit is enabled with physical addressing')         
    @allure.description('Test NRC12 negative response code of 0x28 when suppressPosMsgBit is enabled with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_Supported_NRC12,ids=ids)
    def test_CommunicationControl_SuppressPosMsgBit_NRC12_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_Supported_NRC13] 
    @allure.severity('normal')
    @allure.title('Test NRC13 negative response code of 0x28 when suppressPosMsgBit is enabled with physical addressing')         
    @allure.description('Test NRC13 negative response code of 0x28 when suppressPosMsgBit is enabled with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_Supported_NRC13,ids=ids)
    def test_CommunicationControl_SuppressPosMsgBit_NRC13_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_Supported_NRC31] 
    @allure.severity('normal')
    @allure.title('Test NRC31 negative response code of 0x28 when suppressPosMsgBit is enabled with physical addressing')         
    @allure.description('Test NRC31 negative response code of 0x28 when suppressPosMsgBit is enabled with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_Supported_NRC31,ids=ids)
    def test_CommunicationControl_SuppressPosMsgBit_NRC31_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableRx] 
    @allure.severity('normal')
    @allure.title('Test disable rx of 0x28 with physical addressing')
    @allure.description('Test disable rx of 0x28 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableRx,ids=ids)
    def test_CommunicationControl_DisableRx_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)
        time.sleep(0.5)
        #设置车速大于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',80,iStep)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", 'C5 01', 0, iStep, True)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '28 00 01', '68 00', 0, iStep, False)
        time.sleep(0.5)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", '7F 85 22', 0, iStep, False)
        #设置车速小于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',0,iStep)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableRx] 
    @allure.severity('normal')
    @allure.title('Test disable rx time out to default session of 0x28 with physical addressing')
    @allure.description('Test disable rx time out to default session of 0x28 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableRx,ids=ids)
    def test_CommunicationControl_DisableRx_Timeout_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)
        time.sleep(0.5)
        #设置车速大于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',80,iStep)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", 'C5 01', 0, iStep, True)
        time.sleep(5.5)
        logging.info("wait 5.5s for timeout")
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", '7F 85 7F', 0, iStep, False)
        #设置车速小于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',0,iStep)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableRx] 
    @allure.severity('normal')
    @allure.title('Test disable rx change session to default session of 0x28 with physical addressing')
    @allure.description('Test disable rx change session to default session of 0x28 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableRx,ids=ids)
    def test_CommunicationControl_DisableRx_ChangeDefaultSession_Programming_Phy(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)
        time.sleep(0.5)
        #设置车速大于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',80,iStep)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", 'C5 01', 0, iStep, True)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 01", '50 01', 0, iStep, False)
        time.sleep(0.5)
        logging.info("change session 10 01")
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", '7F 85 7F', 0, iStep, False)
        #设置车速小于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',0,iStep)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableTx] 
    @allure.severity('normal')
    @allure.title('Test disable tx of 0x28 with physical addressing')
    @allure.description('Test disable tx of 0x28 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableTx,ids=ids)
    def test_CommunicationControl_DisableTx_Programming_Phy(self,action,Driver, req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)
        time.sleep(1)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x3E,0x00], [0x7E,0x00], 0, iStep, False)
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableTx] 
    @allure.severity('normal')
    @allure.title('Test disable tx time out to default session of 0x28 with physical addressing')
    @allure.description('Test disable tx time out to default session of 0x28 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableTx,ids=ids)
    def test_CommunicationControl_DisableTx_Timeout_Programming_Phy(self,action,Driver, req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)
        time.sleep(1)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x3E,0x00], [0x7E,0x00], 0, iStep, False)
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True
        time.sleep(5.5)
        logging.info("wait 5.5s for timeout")
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableTx] 
    @allure.severity('normal')
    @allure.title('Test disable tx time out to default session of 0x28 with physical addressing')
    @allure.description('Test disable tx time out to default session of 0x28 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableTx,ids=ids)
    def test_CommunicationControl_DisableTx_Timeout_Programming_Phy(self,action,Driver, req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False)
        time.sleep(1)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x3E,0x00], [0x7E,0x00], 0, iStep, False)
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 01', '50 01', 0, iStep, False)
        logging.info("change session to default session")
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True

class Test_CommunicationControl_Boot_Fun(object):

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl] 
    @allure.severity('normal')
    @allure.title('Test positive response of 0x28 in programming session with function addressing')
    @allure.description('Test positive response of 0x28 in programming session with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl,ids=ids)
    def test_CommunicationControl_Programming_Fun(self,action,Driver, req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun')

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_NRC12]   
    @allure.severity('minor') 
    @allure.title('Test NRC12 of 0x28 in programming session with function addressing')        
    @allure.description('Test NRC12 of 0x28 in programming session with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_NRC12,ids=ids)
    def test_CommunicationControl_NRC12_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun') 

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_NRC13]   
    @allure.severity('minor') 
    @allure.title('Test NRC13 of 0x28 in programming session with function addressing')        
    @allure.description('Test NRC13 of 0x28 in programming session with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_NRC13,ids=ids)
    def test_CommunicationControl_NRC13_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun')    


    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_NRC31]   
    @allure.severity('minor') 
    @allure.title('Test NRC31 of 0x28 in programming session with function addressing')        
    @allure.description('Test NRC31 of 0x28 in programming session with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_NRC31,ids=ids)
    def test_CommunicationControl_NRC31_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun')            


    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_Supported_NRC12] 
    @allure.severity('normal')
    @allure.title('Test NRC12 negative response code of 0x28 when suppressPosMsgBit is enabled with function addressing')         
    @allure.description('Test NRC12 negative response code of 0x28 when suppressPosMsgBit is enabled with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_Supported_NRC12,ids=ids)
    def test_CommunicationControl_SuppressPosMsgBit_NRC12_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun') 

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_Supported_NRC13] 
    @allure.severity('normal')
    @allure.title('Test NRC13 negative response code of 0x28 when suppressPosMsgBit is enabled with function addressing')         
    @allure.description('Test NRC13 negative response code of 0x28 when suppressPosMsgBit is enabled with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_Supported_NRC13,ids=ids)
    def test_CommunicationControl_SuppressPosMsgBit_NRC13_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun') 

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_Supported_NRC31] 
    @allure.severity('normal')
    @allure.title('Test NRC31 negative response code of 0x28 when suppressPosMsgBit is enabled with function addressing')         
    @allure.description('Test NRC31 negative response code of 0x28 when suppressPosMsgBit is enabled with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_Supported_NRC31,ids=ids)
    def test_CommunicationControl_SuppressPosMsgBit_NRC31_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun') 

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableRx] 
    @allure.severity('normal')
    @allure.title('Test disable rx of 0x28 with function addressing')
    @allure.description('Test disable rx of 0x28 with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableRx,ids=ids)
    def test_CommunicationControl_DisableRx_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun') 
        time.sleep(0.5)
        #设置车速大于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',80,iStep)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", 'C5 01', 0, iStep, True)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '28 00 01', '68 00', 0, iStep, False, 'UDSFun')
        time.sleep(0.5)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", '7F 85 22', 0, iStep, False)
        #设置车速小于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',0,iStep)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableRx] 
    @allure.severity('normal')
    @allure.title('Test disable rx timeout to default session of 0x28 with function addressing')
    @allure.description('Test disable rx timeout to default session of 0x28 with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableRx,ids=ids)
    def test_CommunicationControl_DisableRx_Timeout_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun') 
        time.sleep(0.5)
        #设置车速大于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',80,iStep)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", 'C5 01', 0, iStep, True)
        time.sleep(5.5)
        logging.info("wait 5.5s for timeout")
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", '7F 85 7F', 0, iStep, False)
        #设置车速小于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',0,iStep)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableRx] 
    @allure.severity('normal')
    @allure.title('Test disable rx change session to default session of 0x28 with function addressing')
    @allure.description('Test disable rx change session to default session of 0x28 with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableRx,ids=ids)
    def test_CommunicationControl_DisableRx_ChangeDefaultSession_Programming_Fun(self,action,Driver,req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun') 
        time.sleep(0.5)
        #设置车速大于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',80,iStep)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", 'C5 01', 0, iStep, True)
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "10 01", '50 01', 0, iStep, False)
        logging.info("change session to default session")
        iStep, uds_resp, size = Driver['CAN'].checkReqResp(Driver, "85 01", '7F 85 7F', 0, iStep, False)
        #设置车速小于3KM/H
        iStep = Driver['CAN'].setSignalValue('IPB_0x121','IPB_Vehicle_Speed_S',0,iStep)

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableTx] 
    @allure.severity('normal')
    @allure.title('Test disable tx of 0x28 with function addressing')
    @allure.description('Test disable tx of 0x28 with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableTx,ids=ids)
    def test_CommunicationControl_DisableTx_Programming_Fun(self,action,Driver, req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun') 
        time.sleep(1)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x3E,0x00], [0x7E,0x00], 0, iStep, False, 'UDSFun') 
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True    

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableTx] 
    @allure.severity('normal')
    @allure.title('Test disable tx timeout to default session of 0x28 with function addressing')
    @allure.description('Test disable tx timeout to default session of 0x28 with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableTx,ids=ids)
    def test_CommunicationControl_DisableTx_Timeout_Programming_Fun(self,action,Driver, req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun') 
        time.sleep(1)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x3E,0x00], [0x7E,0x00], 0, iStep, False, 'UDSFun') 
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True 
        time.sleep(5.5)
        logging.info("wait 5.5s for timeout")
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True 

    ids = ['Request {0}'.format(binascii.b2a_hex(bytearray(req),' ')) for req,resp in communicationControl_DisableTx] 
    @allure.severity('normal')
    @allure.title('Test disable tx change session to default session of 0x28 with function addressing')
    @allure.description('Test disable tx change session to default session of 0x28 with function addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/630357052177ea2394680877/cases')
    @pytest.mark.parametrize('req,resp',communicationControl_DisableTx,ids=ids)
    def test_CommunicationControl_DisableTx_ChangeDefaultSession_Programming_Fun(self,action,Driver, req,resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, False, 'UDSFun') 
        time.sleep(1)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x3E,0x00], [0x7E,0x00], 0, iStep, False, 'UDSFun') 
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True 
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x10,0x01], [0x50,0x01], 0, iStep, False) 
        logging.info("change session to default session")
        messageCount, iStep = Driver['CAN'].GetTxMessageCount(Driver, iStep)
        with assume: assert all(x == 0 for x in messageCount) == True     
